# -*- coding: utf-8 -*-

import paramiko

def rcmd(host,user,passwd,port=22,cmds=None):

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(host,username=user,password=passwd)

    stdin,stdout,stderr = ssh.exec_command(cmds)

    out = stdout.read()
    err = stderr.read()

    if out:
        print('[%s]\033[32;1mOUT\033[0m:\n%s'%(host,out.decode()))
    if err:
        print('[%s]\033[31;1mERROR\033[0m:\n%s'%(host,err.decode()))

    ssh.close()

if __name__ == '__main__':
    host = '192.168.43.70'
    passwd = 'xuehaoning'
    cmds = 'id root;id dingjie'
    rcmd(host,'root',passwd,22,cmds=cmds)
